package com.woniu.controller;

import com.alibaba.excel.EasyExcel;
import com.woniu.entity.PageData;
import com.woniu.entity.Result;
import com.woniu.entity.dto.PaymentInfoDTO;
import com.woniu.entity.dto.QueryTrainingDTO;
import com.woniu.entity.dto.QueryTrainingLevelDTO;
import com.woniu.pojo.PaymentInfo;
import com.woniu.pojo.TrainingLevel;
import com.woniu.service.ITrainingService;
import com.woniu.service.PaymentInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@RestController
@RequestMapping("/paymentInfo")
@Api(tags = "支付信息表管理")
public class PaymentInfoController extends BaseController{
    @Autowired
    private PaymentInfoService paymentInfoService;

    @ApiOperation("分页+搜索")
    @PostMapping("/listSearch/{currentPage}/{pageSize}")
    public Result listSearch(@PathVariable Integer currentPage,
                             @PathVariable Integer pageSize,
                             @RequestBody PaymentInfoDTO paymentInfoDTO) {
        PageData pageData = paymentInfoService.listSearch(currentPage, pageSize, paymentInfoDTO);
        return toDataResult(pageData);
    }

    @ApiOperation("导出数据")
    @PostMapping("/export")
    public void exportExcel(@RequestBody(required = false) PaymentInfoDTO paymentInfoDTO,
                            HttpServletResponse response) throws IOException {
        PageData pageData = paymentInfoService.listSearch(1, 1000, paymentInfoDTO);
        List<PaymentInfo> paymentInfoList = (List<PaymentInfo>) pageData.getData();
        EasyExcel.write(response.getOutputStream(), PaymentInfo.class).sheet().doWrite(paymentInfoList);
    }
}
